/*
	网站页面控制器
*/
var AV 				= require('leanengine');
var moment		= require('moment');
var mdCommon	= require('../modules/common');
var avBrand 			= AV.Object.extend("Brand");
var avImage 			= AV.Object.extend("Image");
var avItem 				= AV.Object.extend("item");
var avSysConfig 	= AV.Object.extend("SysConfig");

/**
 * 网站首页
 * 2015.04.25  by 胡斌
 */
exports.homePage = function(req,res) {
	//res.redirect('/admin-login');
	var querySysConfig 	= new AV.Query(avSysConfig);
	querySysConfig.equalTo("type","homepage");
	querySysConfig.find().then(function(results) {
		var slides,catagory;
		for(var i=0;i<results.length;i++){
			if(results[i].get("name")=="home_banner"){
				slides=eval("("+results[i].get('value')+")");
			}else if(results[i].get("name")=="home_catagory"){
				catagory=eval("("+results[i].get('value')+")");
			}
		}
		res.render('main/index.html',{
			user:req.AV.user,
			slides:slides,
			catagory:catagory
		});
	},function(error){
		console.dir(error);
		mdCommon.sentErr(res,req,error);
	});/**/
}


admin.doCkAuth = function(req,res,next) {
	//console.log(req.AV.user);
	if(!req.AV.user){// 判断用户是否已经登录
		res.redirect('/login?refer='+req.originalUrl);
		return false;
	}
	next();
}
